﻿using ChessGame.Movement;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChessGame.Pieces
{
    /// <summary>
    /// Base chesspiece object.
    /// </summary>
    public class Chesspiece
    {
        private int pieceValue;
        public int positionX;
        public int positionY;
        private Boolean colour; //True = Wit, False= Black;
        private string type;
        public Movement.Movement startMovement;
        public Movement.Movement movement;
        public Movement.Hit hit;
        public Boolean firstMove;

        /// <summary>
        /// Chesspiece Type
        /// </summary>
        public string Type
        {
            get { return type; }
            set { type = value; }
        }

        /// <summary>
        /// Chesspiece Value
        /// </summary>
        public int PieceValue
        {
            get { return pieceValue; }
            set { pieceValue = value; }
        }

        /// <summary>
        /// Chesspiece BoardPositon
        /// </summary>
        public string BoardPosition
        {
            get {  return NumberToString(positionX)+""+positionY.ToString(); }
        }

        /// <summary>
        /// Chesspiece Colour
        /// </summary>
        public Boolean Colour
        {
            get { return colour; }
            set { colour = value; }
        }

        /// <summary>
        /// Chesspiece Position X
        /// </summary>
        public int PositionX
        {
            get { return positionX; }
            set { positionX = value; }
        }

        /// <summary>
        /// Chesspiece Position Y
        /// </summary>
        public int PositionY
        {
            get { return positionY; }
            set { positionY = value; }
        }

        /// <summary>
        /// Get movement possibilities of this chesspiece
        /// </summary>
        /// <returns>List of MovementOption</returns>
        public List<MovementOption> GetMovementPossibilities()
        {
            if (firstMove)
            {
                return startMovement.GetOptions();
            }
            else
            {
                return movement.GetOptions();
            }
        }
        /// <summary>
        ///  Get hit possibilities of this chesspiece
        /// </summary>
        /// <returns></returns>
        public List<HitOption> GetHitPossibilities()
        {
            return hit.GetOptions();
        }

        /// <summary>
        /// Set a position
        /// </summary>
        /// <param name="_x">Position X</param>
        /// <param name="_y">Position Y</param>
        public void SetPosition(int _x, int _y)
        {
            positionX = _x;
            positionY = _y;
        }

        /// <summary>
        /// Turn this object.
        /// </summary>
        public void Turn()
        {
            firstMove = false;
        }
        /// <summary>
        /// Number to String
        /// </summary>
        /// <param name="number">A number</param>
        /// <returns>String</returns>
        private string NumberToString(int number)
        {
            switch (number)
            {
                case 1:
                    return "A";
                case 2:
                    return "B";
                case 3:
                    return "C";
                case 4:
                    return "D";
                case 5:
                    return "E";
                case 6:
                    return "F";
                case 7:
                    return "G";
                case 8:
                    return "H";
                default:
                    return "";
            }
        }
    }
}
